All Questions
Tagged with programming-practicesjavascript
42 questions
1vote
2answers
328views
Is it a bad habit to use other class' "private" variables in Javascript
I've gotten this idea in my head that i shouldn't use a libraries variable, if the variable name begins with '_', as it is standard to write private variables that way. But now i'm thinking i'm taking ...
0votes
2answers
2kviews
Store static data in public folder as json file or directly in .js file?
I'm busy working on a website – somewhat new to this – and I don't quite know where I should store static data: in the public folder as a separate json file, or within the .js file as an object. In ...
0votes
3answers
125views
Should we test private data (static objects in this case) to make sure it maintains its structure?
I had a discussion at work about whether to unit test a private static object we're using as data for a public component. const data = { 45: { name: 'John' }, 2: { name: 'Patricia' }, 27: { name: '...
11votes
1answer
5kviews
Is it bad practice to require the same module in multiple files in Javascript?
Let’s say I have three files, all of which import a fairly large module. But I’ve divided them because they have different functions. Now each of the JavaScript files needs an initial statement like ...
3votes
1answer
400views
What is the expected performance of While loops using `array.pop()` assignment vs other methods
Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
0votes
2answers
200views
Should we check if the primary key exists if rendering a collection fetched from database?
I have got an argument with my colleagues about this. IMO It's common practice that you don't need to check if an id exists or not before rendering it. So here's an example. This is what my ...
1vote
3answers
4kviews
Good practice for JavaScript (ES6) data objects
I see very often to pass around unnamed data objects in JavaScript, e.g. { a: 1, b: 2}. Is it a good practice or is better to make a simple data class for that like in other languages: class ...
2votes
1answer
211views
Which programming pattern is best for checking which partition a number lies in?
I have an interval partitioned into “MECE” subintervals, and I want to check which subinterval a number lies in. (MECE stands for “mutually exclusive & collectively exhaustive”, meaning the ...
0votes
1answer
682views
Why "typeof null == object" will stay in javascript?
I was reading a article about front-end development on Medium, when I stumbled upon an interesting piece of information, which is as follows: The type of a variable can be determined by using the ...
3votes
1answer
158views
What is the standard method of handling errors in a NodeJS web app?
I am currently working on a web application as a learning project, which has a NodeJS backend and uses a MongoDB database; however, I believe my question is not specific to the technologies I am using....
1vote
2answers
2kviews
Best Practices - Including endpoint URL calls in JavaScript vs backend calls
I am building a web application that will retrieve results from a remote server and use them to render some charts and maps. The remote server has already been implemented and contains a large amount ...
1vote
0answers
1kviews
What are the best practices for picking selectors for web scrappers?
The following is an example using https://github.com/GoogleChrome/puppeteer 'use strict'; const puppeteer = require('puppeteer'); (async() => { // const browser = await puppeteer.launch(); // ...
17votes
4answers
7kviews
Why does Facebook obfuscate the names of CSS classes?
If you look at the source code of a website such as Facebook, you'll see many classes as such: <div class="_cy6 _2s24"><div class="_4kny"><div class="uiToggle _8-a _1kj2 _4d1i _-57 _5-...
-1votes
1answer
331views
Modelling research paper data in JSON
I need to design an UI to edit a research paper, I don't have enough knowledge about the research domain but still I tried to do my best and thought to design a normalized schema. I am describing the ...
1vote
0answers
85views
Capturing keyboard events for a limited time
I'm trying to code a kind of simple video game where there are two kind of players: Human Players: They enter an keyboard input CPU Players: A random input is calculated For Human Players there is a T ...